package com.story.api.moduler.user.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.story.api.common.result.ServerResponse;
import com.story.api.config.properties.SubMailProperties;
import com.story.api.moduler.user.service.MessageService;
import com.submail.lib.MESSAGEXsend;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Administrator
 * @decription 短信发送
 * @Date 2018-02-02 10:11
 */
@Service
public class MessageServiceImpl implements MessageService {

    @Autowired
    private MESSAGEXsend messageXsend;

    @Autowired
    private SubMailProperties subMailProperties;

    @Override
    public ServerResponse sendMessage(String phone, String code) {
        messageXsend.addTo(phone);
        messageXsend.setProject(subMailProperties.getProjectName());
        messageXsend.addVar("code",code);
        String result = messageXsend.xsend();
        JSONObject jsonObject = JSONObject.parseObject(result);
        String status = (String) jsonObject.get("status");
        if("success".equals(status)) {
            return ServerResponse.getSuccess("success");
        } else {
            return ServerResponse.getSuccess(status);
        }
    }
}
